import { Body, Controller, Get, Post, Query, Res } from "@nestjs/common"
import { WechatPayService } from "./wechatPay.service"
import { Response } from "express"

@Controller("/wechatPay")
export class WechatPayController {
  constructor(private readonly wechatPayService: WechatPayService) {}

  // Initiation of payment
  @Get("pay")
  async doPay(@Query() query: object, @Res() res: object): Promise<void> {
    return await this.wechatPayService.doPay(query, res)
  }

  // Payment callback
  @Post("/notify")
  async notify(@Body() body: any, @Res() res: Response): Promise<void> {
    return await this.wechatPayService.notify(body, res)
  }

  // Obtain payment configuration
  @Get("/getConfig")
  async getConfig(@Res() res: any): Promise<void> {
    return this.wechatPayService.getConfig(res)
  }

  // Save payment configuration
  @Post("/saveConfig")
  async saveConfig(@Body() body: any, @Res() res: any): Promise<void> {
    return await this.wechatPayService.saveConfig(body, res)
  }

  // Whether the payment is open
  @Get("/isOpen")
  async isOpen(@Res() res: Response): Promise<void> {
    return await this.wechatPayService.isOpen(res)
  }
}
